package com.lehecai.core.api.event;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.event.EventInfoStatus;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.*;

/**
 * Created by zhangzq on 14-11-14.
 */
public class EventCollectInfo extends AbstractApiResultBean {

    public static final String QUERY_EVENT_ID = "event_id";
    public static final String QUERY_EVENT_NAME = "event_name";
    public static final String QUERY_EVENT_STATUS = "event_status";
    public static final String QUERY_EVENT_START_TIME = "event_time_start";
    public static final String QUERY_EVENT_END_TIME = "event_time_end";
    public static final String QUERY_EVENT_TIMELINE = "timeline";
    public static final String QUERY_EVENT_EVENTTYPE = "type";

    public static final String SET_EVENT_ID = "event_id";
    public static final String SET_EVENT_NAME = "event_name";
    public static final String SET_EVENT_DESCRIPTION = "event_description";
    public static final String SET_EVENT_START_TIME = "event_time_start";
    public static final String SET_EVENT_END_TIME = "event_time_end";
    public static final String SET_TIME_LINE = "timeline";
    public static final String SET_LINK = "link";
    public static final String SET_IMG_SRC = "img_src";
    public static final String SET_TOP = "top";
    public static final String SET_TOP_SRC = "top_src";
    public static final String SET_PRIORITY = "priority";
    public static final String SET_EVENT_STATUS = "event_status";
    public static final String SET_EVENT_TYPE = "type";
    public static final String SET_USER_TYPE = "user_type";
    public static final String SET_SOURCE = "source";
    public static final String SET_AD_SRC = "ad_src";

    public static final String ORDER_EVENT_START_TIME = "event_time_start";
    public static final String ORDER_EVENT_END_TIME = "event_time_end";
    public static final String ORDER_PRIORITY = "priority";


    private Integer eventId;			         //活动ID
    private String eventName;                //活动名称
    private String eventDescription;	     //活动描述
    private Date eventStartTime;             //活动起始时间
    private Date eventEndTime;               //活动结束时间
    private Date timeline;                   //活动创建时间
    private String link;                     //活动链接
    private String imgSrc;                   //活动图片
    private YesNoStatus top;                 //是否置顶
    private String topSrc;                   //置顶图片
    private String adSrc;                    //广告位图片
    private Integer priority;                //排序值
    private EventType eventType;             //活动类型
    private UserType userType;               //适用人群
    private ChannelsType channelsType;       //推广渠道
    private EventInfoStatus eventStatus;     //0,活动关闭  1,活动开启

    public static EventCollectInfo convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        EventCollectInfo eventCollectInfo = new EventCollectInfo();

        eventCollectInfo.setEventId(getInt(object, "event_id"));
        eventCollectInfo.setEventName(getString(object, "event_name"));
        eventCollectInfo.setEventDescription(getString(object, "event_description"));
        eventCollectInfo.eventStartTime = CoreDateUtils.parseDate(("".equals(getString(object, "event_time_start")) || "0000-00-00 00:00:00".equals(getString(object, "event_time_start"))) ? null : getString(object, "event_time_start"), CoreDateUtils.DATETIME);
        eventCollectInfo.eventEndTime = CoreDateUtils.parseDate(("".equals(getString(object, "event_time_end")) || "0000-00-00 00:00:00".equals(getString(object, "event_time_end"))) ? null : getString(object, "event_time_end"), CoreDateUtils.DATETIME);
        eventCollectInfo.timeline = CoreDateUtils.parseDate(("".equals(getString(object, "timeline")) || "0000-00-00 00:00:00".equals(getString(object, "timeline"))) ? null : getString(object, "timeline"), CoreDateUtils.DATETIME);
        eventCollectInfo.setLink(getString(object, "link"));
        eventCollectInfo.setImgSrc(getString(object, "img_src"));
        eventCollectInfo.setTop(YesNoStatus.getItem(getInt(object, "top")));
        eventCollectInfo.setTopSrc(getString(object, "top_src"));
        eventCollectInfo.setPriority(getInt(object, "priority"));
        eventCollectInfo.setEventType(EventType.getItem(getInt(object, "type")));
        eventCollectInfo.setUserType(UserType.getItem(getInt(object, "user_type")));
        eventCollectInfo.setChannelsType(ChannelsType.getItem(getInt(object, "source")));
        eventCollectInfo.setEventStatus(EventInfoStatus.getItem(getInt(object, "event_status")));
        if (object.containsKey("ad_src")) {
            eventCollectInfo.setAdSrc(getString(object, "ad_src"));
        }

        return eventCollectInfo;
    }

    public static List<EventCollectInfo> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<EventCollectInfo> list = new ArrayList<EventCollectInfo>();
        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public Integer getEventId() {
        return eventId;
    }

    public void setEventId(Integer eventId) {
        this.eventId = eventId;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public String getEventDescription() {
        return eventDescription;
    }

    public void setEventDescription(String eventDescription) {
        this.eventDescription = eventDescription;
    }

    public Date getEventStartTime() {
        return eventStartTime;
    }

    public void setEventStartTime(Date eventStartTime) {
        this.eventStartTime = eventStartTime;
    }

    public Date getEventEndTime() {
        return eventEndTime;
    }

    public void setEventEndTime(Date eventEndTime) {
        this.eventEndTime = eventEndTime;
    }

    public Date getTimeline() {
        return timeline;
    }

    public void setTimeline(Date timeline) {
        this.timeline = timeline;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getImgSrc() {
        return imgSrc;
    }

    public void setImgSrc(String imgSrc) {
        this.imgSrc = imgSrc;
    }

    public YesNoStatus getTop() {
        return top;
    }

    public void setTop(YesNoStatus top) {
        this.top = top;
    }

    public String getTopSrc() {
        return topSrc;
    }

    public void setTopSrc(String topSrc) {
        this.topSrc = topSrc;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public EventType getEventType() {
        return eventType;
    }

    public void setEventType(EventType eventType) {
        this.eventType = eventType;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    public ChannelsType getChannelsType() {
        return channelsType;
    }

    public void setChannelsType(ChannelsType channelsType) {
        this.channelsType = channelsType;
    }

    public EventInfoStatus getEventStatus() {
        return eventStatus;
    }

    public void setEventStatus(EventInfoStatus eventStatus) {
        this.eventStatus = eventStatus;
    }

    public String getAdSrc() {
        return adSrc;
    }

    public void setAdSrc(String adSrc) {
        this.adSrc = adSrc;
    }
}
